<template>
	<div class="modal fade" data-backdrop="static">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title" id="myModalLabel">课程详细内容</h4>
				</div>
				<div class="modal-body">
					<span>每30秒自动保存一次</span>
					<div id="summernote"></div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" @click="save(true)">保存</button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	export default {
		props: {
			course: Object
		},
		mounted() {

		},
		methods: {
			save(isClick) {
				let url = process.env.VUE_APP_SERVER + 'business/admin/course/saveContent'
				let content = $('#summernote').summernote('code')
				if(!this.$global.validator.require(content, '课程内容')) return
				this.$axios.post(url, {id: this.course.id, content: content})
					.then(res => {
						if (res.data.status === 1) {
							this.$toast('课程内容保存成功', this.$global.toast.success)
							if(isClick) $('#content-modal').modal('hide')
						} else {
							this.$toast(res.data.msg, this.$global.toast.fail)
						}
					})
			}
		}
	}
</script>

<style>
</style>
